// Copyright  2012 Petr TALLA. [petr.talla@gmail.com]
// This file is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This file is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY;  without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
// [http://www.gnu.org/copyleft/lesser.html]
//=============================================================================
package tc.common.registry;

import java.util.LinkedHashMap;
import java.util.Vector;

public class Registry {
	public LinkedHashMap<Integer, Obj> objects = new LinkedHashMap<Integer, Obj>();
	
	public Vector<Obj> changed = new Vector<Obj>();
	public Vector<Rview> views = new Vector<Rview>();

	private int locker = 0;
	
	public void lock() {
		locker++;
	}
	
	public void unlock() {
		if (--locker > 0) return;
		
		for (int i = 0; i < views.size(); i++) {
			views.get(i).checkPresence();		
		}
		
		for ( int i = 0; i < changed.size(); i++) {
			changed.get(i).sendChangedMsg();
		}
			
		for (int i = 0; i < views.size(); i++) {
			Rview view = views.get(i); 
			if (view.getDirty()) view.updateRview(); 		
		}
		
		for (int i = 0; i < changed.size(); i++) {
			changed.get(i).state = Obj.State.CURRENT;
		}
		
		changed.clear();
	}
}


